feat: add xmodem cp upload/download command#915
Draft
benallfree wants to merge 9 commits into
Draft
Conversation
Closed
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds XMODEM-based file transfer support to the Meshtastic Python library and CLI, enabling device-side file upload/download plus directory listing and download planning for trees/globs.
Changes:
- Added XMODEM transfer helpers to
Node(uploadFile,downloadFile,listDir) plus CRC16 support. - Added CLI planning utilities for uploads/downloads (including local globs and remote tree/glob planning).
- Wired new CLI flags (
--upload,--download,--download-tree,--download-glob,--ls) and added unit tests for the new functionality.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
| meshtastic/node.py | Implements XMODEM send/receive logic, CRC16, and Node-level upload/download/listDir APIs. |
| meshtastic/file_transfer_cli.py | Adds reusable path/glob planning helpers for CLI-driven multi-file transfers. |
| meshtastic/main.py | Adds CLI arguments and integrates the new transfer operations into the CLI workflow. |
| meshtastic/tests/test_node.py | Adds unit tests covering XMODEM CRC, upload/download flows, and MFLIST parsing behavior. |
| meshtastic/tests/test_file_transfer_cli.py | Adds unit tests for upload/download planning helpers (globs, tree/glob selection). |
| return False | ||
|
|
||
| try: | ||
| data = open(local_path, "rb").read() |
Comment on lines
+1159
to
+1164
|
|
||
| # SOH seq=0 — filename handshake | ||
| xm = xmodem_pb2.XModem() | ||
| xm.control = XC.SOH | ||
| xm.seq = 0 | ||
| xm.buffer = device_path.encode("utf-8")[: self._XMODEM_BUFFER_MAX] |
Comment on lines
+1113
to
+1116
| def _on_xmodem(packet, interface): | ||
| result[0] = packet | ||
| event.set() | ||
|
|
Comment on lines
+1264
to
+1267
| xm = xmodem_pb2.XModem() | ||
| xm.control = XC.STX | ||
| xm.seq = 0 | ||
| xm.buffer = device_path.encode("utf-8")[: self._XMODEM_BUFFER_MAX] |
Comment on lines
+1269
to
+1270
| chunks: list = [] | ||
| expected_seq = 1 |
| if sz <= 0: | ||
| continue | ||
| path = path.replace("\\", "/") | ||
| if not path.startswith(remote_dir): |
Comment on lines
+231
to
+236
| tail = path[len(remote_dir) :].lstrip("/") | ||
| if not tail: | ||
| continue | ||
| local_path = os.path.join(local_root, *tail.split("/")) | ||
| out.append((path, os.path.normpath(local_path))) | ||
|
|
Comment on lines
+264
to
+271
| rel = path[len(base_n) :].lstrip("/") | ||
| if not rel: | ||
| continue | ||
| if not rx.match(rel): | ||
| continue | ||
| local_path = os.path.join(local_root, *rel.split("/")) | ||
| out.append((path, os.path.normpath(local_path))) | ||
|
|
Comment on lines
+1
to
+10
| """Tests for meshtastic.file_transfer_cli.""" | ||
|
|
||
| import os | ||
| import tempfile | ||
|
|
||
| import pytest | ||
|
|
||
| from meshtastic.file_transfer_cli import ( | ||
| FileTransferCliError, | ||
| XMODEM_DEVICE_PATH_UTF8_MAX, |
Comment on lines
+1225
to
+1228
| def _cb(packet, interface): | ||
| result[0] = packet | ||
| event.set() | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds support for Meshtastic's XMODEM-based file copy feature.
Prerequisites:
Merge Feat/vfs ls and xmodem ls firmware#10151
Added
--uploadand--downloadcommands with globbing